﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace csharp_time
{
    class Program
    {
        static void Main(string[] args)
        {
            ConsoleKeyInfo consoleKeyInfo;

            do
            {
                fnPrintMode();
                consoleKeyInfo = Console.ReadKey();
                Console.WriteLine("");
                switch (consoleKeyInfo.Key)
                {
                    case ConsoleKey.NumPad1:
                    case ConsoleKey.D1:
                        fnLastDayMode();
                        break;
                    case ConsoleKey.NumPad2:
                    case ConsoleKey.D2:
                        fnSleepMode();
                        break;
                    case ConsoleKey.NumPad3:
                    case ConsoleKey.D3:
                        fnYoonYearMode();
                        break;
                    case ConsoleKey.NumPad4:
                    case ConsoleKey.D4:
                        fnTime2StringMode();
                        break;

                }
            } while (!consoleKeyInfo.Key.Equals(ConsoleKey.Q));
        }

        static void fnPrintMode()
        {
            Console.WriteLine("1. last day");
            Console.WriteLine("2. sleep(milli)");
            Console.WriteLine("3. yoon year");
            Console.WriteLine("4. time2string");
            Console.WriteLine("q. quit");
        }

        static void fnLastDayMode()
        {
            Console.Write("input year: ");
            string input_year = Console.ReadLine();

            Console.Write("input month: ");
            string input_month = Console.ReadLine();

            int lastDay = fnLastDay(Convert.ToInt32(input_year), Convert.ToInt32(input_month));
            Console.WriteLine(lastDay);
        }

        static int fnLastDay(int year, int month)
        {
            return DateTime.DaysInMonth(year, month);
        }

        static void fnSleepMode()
        {
            Console.Write("input delay: ");
            string input_delay = Console.ReadLine();

            Console.WriteLine(DateTime.Now);

            fnSleep(Convert.ToInt32(input_delay));

            Console.WriteLine(DateTime.Now);
        }

        static void fnSleep(int milli)
        {
            Thread.Sleep(milli);
        }

        static void fnYoonYearMode()
        {
            Console.Write("input year: ");
            string input_year = Console.ReadLine();

            Boolean yoonYear = fnYoonYear(Convert.ToInt32(input_year));
            Console.WriteLine(yoonYear);
        }

        static Boolean fnYoonYear(int year)
        {
            return DateTime.IsLeapYear(year);
        }

        static void fnTime2StringMode()
        {
            DateTime now = DateTime.Now;
            string time2String = String.Format("{0:yyyy-MM-dd HH:mm:ss}", now);
            Console.WriteLine(time2String);
        }
    }
}
